import { IParam } from '../../common';
import { IController, IEvent } from '../../modules/common';
import { ICtrlAbility } from '../../widgets';
import { IViewAbility } from '../ability';
import { IViewActionResult } from '../data-action';
import { IViewStore } from '../store';

/**
 * 视图控制器接口
 *
 * @export
 * @interface IViewController
 * @extends {IController}
 */
export interface IViewController<S extends IViewStore, A extends IViewAbility>
	extends IController<S, A> {
	/**
	 * 视图初始化
	 *
	 * @param {IParam} opts
	 * @memberof IViewController
	 */
	viewInit(opts: IParam): void;

	/**
	 * 视图挂载
	 *
	 * @param {IParam} [opts] 额外参数
	 * @memberof IViewController
	 */
	viewMounted(opts?: IParam): void;

	/**
	 * 视图销毁
	 *
	 * @memberof IViewController
	 */
	viewDestroy(): void;

	/**
	 * 关闭视图
	 *
	 * @memberof IViewController
	 */
	closeView(): void;

	/**
	 * 刷新视图
	 *
	 * @memberof IViewController
	 */
	refresh(args?: IParam): Promise<IViewActionResult>;

	/**
	 * 加载视图
	 *
	 * @memberof IViewController
	 */
	load(args?: IParam): Promise<IViewActionResult>;

	/**
	 * 保存视图
	 *
	 * @memberof IViewController
	 */
	save(args?: IParam): void;

	/**
	 * 部件初始化
	 *
	 * @memberof IViewController
	 */
	handleCtrlInit(name: string, ability: ICtrlAbility): void;

	/**
	 * 处理部件行为
	 *
	 * @param {string} name
	 * @param {string} action
	 * @param {*} [data]
	 * @memberof IViewController
	 */
	handleCtrlAction(name: string, action: string, data: IParam[]): void;

	/**
	 * 处理部件销毁
	 *
	 * @param {string} name
	 * @param {IParam} data
	 * @memberof IViewController
	 */
	handleCtrlDestroy(name: string, data: IParam): void;

	/**
	 * 处理组件行为
	 *
	 * @param {IEvent<string>} actionParam
	 * @param {number} [index]
	 * @memberof IViewController
	 */
	handleComponentAction(actionParam: IEvent<string>, index?: number): void;

	/**
	 * 处理部件销毁
	 *
	 * @param {string} name
	 * @param {IParam} data
	 * @memberof IViewController
	 */
	handleCtrlDestroy(name: string, data: IParam): void;

	/**
	 * 初始化视图消息组
	 *
	 * @return {*}  {A}
	 * @memberof ViewController
	 */
	initViewMsg(): void;
}
